home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / FEOF.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  548 b   |  26 lines

  1. /* feof.c */
  2. #include <stdio.h>
  3. main()
  4. {
  5.      FILE *infile;
  6.      unsigned char buffer[81];
  7.         /* Open the file "c:\autoexec.bat". We need two '\' */
  8.     if ((infile = fopen("c:\\autoexec.bat", "r")) == NULL)
  9.     {
  10.         perror ("fopen failed.\n");
  11.         exit(0);
  12.     }
  13.     printf("Contents of c:\autoexec.bat:\n");
  14.     while (fgets(buffer, 80, infile) != NULL)
  15.     {
  16.         printf(buffer);
  17.     }
  18.     if (feof(infile) != 0)    /* Check end-of-file */
  19.     {
  20.         printf("*** End-of-file reached ***");
  21.     }
  22.     else
  23.     {
  24.         printf("ERROR: reading from file!\n");
  25.     }
  26. }